from django.db import models
from course.models import Course, UserCourseContact, Member


# Create your models here.
class Question(models.Model):
    CHOICE = "1.0"
    COMPLETION = "2.0"

    QUESTION_TYPE = [
        (CHOICE, "选择题"),
        (COMPLETION, "填空题"),
    ]
    question_type = models.CharField("问题类型", max_length=20, choices=QUESTION_TYPE)
    question_title = models.CharField("问题内容", max_length=255)
    course = models.ForeignKey(Course, max_length=255, on_delete=models.CASCADE)
    question_chapter = models.CharField("问题所属章节", max_length=255)
    question_optionA = models.CharField("选择题A选项", blank=True, null=True, max_length=255)
    question_optionB = models.CharField("选择题B选项", blank=True, null=True, max_length=255)
    question_optionC = models.CharField("选择题C选项", blank=True, null=True, max_length=255)
    question_optionD = models.CharField("选择题D选项", blank=True, null=True, max_length=255)
    question_answer = models.CharField("问题答案", max_length=255)
    create_time = models.DateTimeField("课程创建时间", auto_now_add=True)
    update_time = models.DateTimeField("课程更新时间", auto_now=True)

    class Meta:
        db_table = "question"
        ordering = ["question_type"]

    def __str__(self):
        return self.question_answer


class Coption(models.Model):
    cid = models.CharField(max_length=10, primary_key=True)
    ccontent = models.CharField(max_length=200)
    coA = models.CharField(max_length=50)
    coB = models.CharField(max_length=50)
    coC = models.CharField(max_length=50)
    coD = models.CharField(max_length=50)


class CoptionAnswer(models.Model):
    class Answer:
        A = 'A'
        B = 'B'
        C = 'C'
        D = 'D'

    options = [
        (Answer.A, 'A'),
        (Answer.B, 'B'),
        (Answer.C, 'C'),
        (Answer.D, 'D')
    ]

    cid = models.CharField(max_length=10, primary_key=True)
    answer = models.CharField(max_length=20, choices=options)


class ErrorQuestion(models.Model):
    user_id = models.CharField(max_length=10)
    question_id = models.CharField(max_length=20)


class User_log(models.Model):
    user_id = models.CharField(max_length=10)
    right_number = models.IntegerField()
    wrong_number = models.IntegerField()
    time = models.DateTimeField(max_length=19)
